package cn.com.swan.framework.module.roleoperation.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import cn.com.swan.framework.dao.BaseDao;
import cn.com.swan.framework.exception.SwanException;
import cn.com.swan.framework.global.PageBean;
import cn.com.swan.framework.module.roleoperation.model.Roleoperation;
import cn.com.swan.framework.module.roleoperation.service.RoleoperationManager;

public class RoleoperationManagerImpl implements RoleoperationManager {
	
	BaseDao baseDao = null;

	public BaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}


	public void createRoleoperation(Roleoperation Roleoperation) throws SwanException {
		getBaseDao().create(Roleoperation);
		
	}

	public void deleteRoleoperation(Roleoperation Roleoperation) throws SwanException {
		getBaseDao().delete(Roleoperation);		
	}

	public void updateRoleoperation(Roleoperation Roleoperation) throws SwanException {
		getBaseDao().update(Roleoperation);
		
	}

	public List<Roleoperation> queryRoleoperation(Roleoperation Roleoperation,
			PageBean pageBean, String orderBy, Boolean isAsc)
			throws SwanException {
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Roleoperation.class);
//		if(Roleoperation.getClassName()!=null && !"".equals(Roleoperation.getClassName())){
//			detachedCriteria.add(Restrictions.like("className", Roleoperation.getClassName(),MatchMode.ANYWHERE));
//		}
		if(Roleoperation.getOperationId()!=null && !"".equals(Roleoperation.getOperationId())){
			detachedCriteria.add(Restrictions.eq("operationId", Roleoperation.getOperationId()));
		}
		if(Roleoperation.getRoleId()!=null && !"".equals(Roleoperation.getRoleId())){
			detachedCriteria.add(Restrictions.eq("roleId", Roleoperation.getRoleId()));
		}
		return getBaseDao().queryByCriteria(detachedCriteria, pageBean, orderBy, isAsc);
	}

	public Roleoperation queryRoleoperation(String entityId) throws SwanException {
		return (Roleoperation) getBaseDao().load(Roleoperation.class, entityId);
	}

}
